﻿using System;
using System.Collections.Generic;

using System.Text;
using System.IO;

namespace Estimate.Common.DataFileFinder
{
    /// <summary>
    /// 降水等值线预报文件发现类
    /// </summary>
    public class RainForeFinder:IDataFileFinder
    {
        public string[] GetFileFromDirectory(DateTime dt, string dirPath)
        {
            if (!checkDateValide(dt))
                return new string[] { };
            string filename;
            List<string> result = new List<string>();
            string[] clockstr = { "08", "20" };
            string[] spanstr = { "012", "021", "024", "048", "072", "096", "120", "144", "168" };

            foreach (string clock in clockstr)
            {
                for (int j = 0; j < spanstr.Length; j++)
                {
                    filename = "PR" + dt.ToString("MMdd" + clock + "." + spanstr[j]);
                    
                    if (File.Exists(dirPath + filename))
                    {                        
                            result.Add(dirPath + filename);                        
                    }
                }
            }
            return result.ToArray();
        }

        /// <summary>
        /// RainFore 的源文件夹存储及命名规范，导致拿不到早于1年的数据
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private bool checkDateValide(DateTime dt)
        {
            DateTime now = DateTime.Now;
            DateTime same_day_of_last_year = now.AddYears(-1).AddDays(2);
            if (dt <= same_day_of_last_year)
                return false;
            return true;
        }


        public string[] GetFileNames(DateTime dt)
        {
            throw new NotImplementedException();
        }


        public Dictionary<string, string[]> GetFileListFromDirectory(DateTime dt, string dirPath)
        {
            throw new NotImplementedException();
        }
    }
}
